package edu.qhst.user.feign;

import edu.qhst.common.constant.ApiRouterConsts;
import edu.qhst.common.resp.BaseResponse;
import edu.qhst.common.resp.ResultUtils;
import edu.qhst.user.dto.UserSafeInfoDto;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户微服务调用客户端
 *
 * @author 加浓美式
 * @date 2023/6/23
 */
@Component
@FeignClient(value = "qhst-user-service", fallback = UserFeign.UserFeignFallback.class)
public interface UserFeign {
    /**
     * 批量查询用户信息
     */
    @PostMapping(ApiRouterConsts.API_INNER_USER_URL_PREFIX + "/listUserInfoByIds")
    BaseResponse<List<UserSafeInfoDto>> listUserInfoByIds(List<Long> userIds);

    /**
     * 获取当前用户信息
     *
     * @param userId
     * @return
     */
    @Operation(summary = "查询当前登录用户")
    @GetMapping("/getUserById")
    UserSafeInfoDto getUserById(Long userId);

    /**
     * 获取当前用户权限
     *
     * @param loginUser
     * @return
     */
    @Operation(summary = "查看用户权限")
    @PostMapping("/isAdmin")
    boolean getUserRole(UserSafeInfoDto loginUser);

    @Component
    class UserFeignFallback implements UserFeign {

        @Override
        public BaseResponse<List<UserSafeInfoDto>> listUserInfoByIds(List<Long> userIds) {
            return ResultUtils.success(new ArrayList<>(0));
        }

        @Override
        public UserSafeInfoDto getUserById(Long userId) {
            return new UserSafeInfoDto();
        }

        @Override
        public boolean getUserRole(UserSafeInfoDto loginUser) {
            return false;
        }
    }
}
